/*!
    \copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \version    
    \file       google_finder_pddu.c
    \ingroup    google_finder
    \brief      The Persistent Device Data User (PDDU) implementation for Google Finder.
*/

#ifdef INCLUDE_GOOGLE_FINDER
#include <panic.h>
#include <string.h>
#include <stdio.h>
#include <logging.h>
#include "google_finder_pddu.h"
#include "device_properties.h"

void googleFinder_SerialisePersistentDeviceData(device_t device, void *buf, pdd_size_t offset)
{
    UNUSED(offset);

    google_finder_pddu_t *google_finder_pddu = NULL;
    size_t google_finder_pddu_size = 0;
    uint8 * buffer = buf;

    if(Device_GetProperty(device, device_property_google_finder, (void *)&google_finder_pddu, &google_finder_pddu_size))
    {
        DEBUG_LOG_INFO("googleFinder_SerialisePersistentDeviceData serialise size=%d", google_finder_pddu_size);
        memcpy(buffer, google_finder_pddu, google_finder_pddu_size);
    }
    else
    {
       DEBUG_LOG("googleFinder_SerialisePersistentDeviceData: Device Get Property failed. ");
    }
}

void googleFinder_DeserialisePersistentDeviceData(device_t device, void *buf, pdd_size_t data_length, pdd_size_t offset)
{
    UNUSED(offset);

    uint8 * buffer = buf;

    DEBUG_LOG_VERBOSE("googleFinder_DeserialisePersistentDeviceData data_length = %d", data_length);

    Device_SetProperty(device, device_property_google_finder, buffer, data_length);
}

pdd_size_t googleFinder_GetDeviceDataLen(device_t device)
{
    google_finder_pddu_t *google_finder_pddu = NULL;
    size_t google_finder_pddu_size = 0;

    if(device != NULL)
    {
        if(Device_GetProperty(device, device_property_google_finder, (void *)&google_finder_pddu, &google_finder_pddu_size))
        {
            DEBUG_LOG_INFO("googleFinder_GetDeviceDataLen size=%d", google_finder_pddu_size);
            return google_finder_pddu_size;
        }
    }

    return 0;
}

#endif /* INCLUDE_GOOGLE_FINDER */
